from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-07 14:04:48.752662
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 07, Jan, 2022
Time: 14:04:54
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6441
Nobs: 529.000 HQIC: -48.0863
Log likelihood: 6128.49 FPE: 9.83737e-22
AIC: -48.3707 Det(Omega_mle): 8.31153e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.392465 0.073763 5.321 0.000
L1.Burgenland 0.101448 0.043036 2.357 0.018
L1.Kärnten -0.113496 0.022175 -5.118 0.000
L1.Niederösterreich 0.175287 0.089520 1.958 0.050
L1.Oberösterreich 0.107641 0.089176 1.207 0.227
L1.Salzburg 0.271652 0.045438 5.979 0.000
L1.Steiermark 0.028428 0.059847 0.475 0.635
L1.Tirol 0.110166 0.048201 2.286 0.022
L1.Vorarlberg -0.077594 0.042648 -1.819 0.069
L1.Wien 0.009885 0.078999 0.125 0.900
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055210 0.162209 0.340 0.734
L1.Burgenland -0.040946 0.094639 -0.433 0.665
L1.Kärnten 0.039945 0.048765 0.819 0.413
L1.Niederösterreich -0.212386 0.196860 -1.079 0.281
L1.Oberösterreich 0.455717 0.196102 2.324 0.020
L1.Salzburg 0.289111 0.099920 2.893 0.004
L1.Steiermark 0.116659 0.131606 0.886 0.375
L1.Tirol 0.307189 0.105997 2.898 0.004
L1.Vorarlberg 0.018899 0.093786 0.202 0.840
L1.Wien -0.020225 0.173722 -0.116 0.907
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.207433 0.037712 5.501 0.000
L1.Burgenland 0.092862 0.022002 4.221 0.000
L1.Kärnten -0.007434 0.011337 -0.656 0.512
L1.Niederösterreich 0.230496 0.045768 5.036 0.000
L1.Oberösterreich 0.159513 0.045591 3.499 0.000
L1.Salzburg 0.041686 0.023230 1.794 0.073
L1.Steiermark 0.025767 0.030597 0.842 0.400
L1.Tirol 0.083539 0.024643 3.390 0.001
L1.Vorarlberg 0.054357 0.021804 2.493 0.013
L1.Wien 0.113128 0.040388 2.801 0.005
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.135278 0.037727 3.586 0.000
L1.Burgenland 0.039574 0.022011 1.798 0.072
L1.Kärnten -0.014639 0.011342 -1.291 0.197
L1.Niederösterreich 0.164919 0.045786 3.602 0.000
L1.Oberösterreich 0.333946 0.045610 7.322 0.000
L1.Salzburg 0.106968 0.023240 4.603 0.000
L1.Steiermark 0.108508 0.030609 3.545 0.000
L1.Tirol 0.093338 0.024653 3.786 0.000
L1.Vorarlberg 0.053599 0.021813 2.457 0.014
L1.Wien -0.022212 0.040405 -0.550 0.583
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.095271 0.071720 1.328 0.184
L1.Burgenland -0.041567 0.041844 -0.993 0.321
L1.Kärnten -0.046049 0.021561 -2.136 0.033
L1.Niederösterreich 0.146216 0.087041 1.680 0.093
L1.Oberösterreich 0.174976 0.086706 2.018 0.044
L1.Salzburg 0.280875 0.044179 6.358 0.000
L1.Steiermark 0.063212 0.058189 1.086 0.277
L1.Tirol 0.154700 0.046866 3.301 0.001
L1.Vorarlberg 0.093392 0.041467 2.252 0.024
L1.Wien 0.083062 0.076811 1.081 0.280
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.094908 0.055601 1.707 0.088
L1.Burgenland 0.019509 0.032440 0.601 0.548
L1.Kärnten 0.051955 0.016715 3.108 0.002
L1.Niederösterreich 0.183277 0.067479 2.716 0.007
L1.Oberösterreich 0.325815 0.067219 4.847 0.000
L1.Salzburg 0.041952 0.034250 1.225 0.221
L1.Steiermark -0.002071 0.045111 -0.046 0.963
L1.Tirol 0.126511 0.036333 3.482 0.000
L1.Vorarlberg 0.062512 0.032147 1.945 0.052
L1.Wien 0.096719 0.059548 1.624 0.104
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159728 0.067614 2.362 0.018
L1.Burgenland 0.011327 0.039449 0.287 0.774
L1.Kärnten -0.065593 0.020327 -3.227 0.001
L1.Niederösterreich -0.109584 0.082058 -1.335 0.182
L1.Oberösterreich 0.215034 0.081742 2.631 0.009
L1.Salzburg 0.050253 0.041650 1.207 0.228
L1.Steiermark 0.254468 0.054858 4.639 0.000
L1.Tirol 0.499008 0.044183 11.294 0.000
L1.Vorarlberg 0.065487 0.039093 1.675 0.094
L1.Wien -0.076206 0.072414 -1.052 0.293
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170172 0.074702 2.278 0.023
L1.Burgenland -0.005938 0.043584 -0.136 0.892
L1.Kärnten 0.063620 0.022458 2.833 0.005
L1.Niederösterreich 0.171944 0.090660 1.897 0.058
L1.Oberösterreich -0.076302 0.090311 -0.845 0.398
L1.Salzburg 0.208677 0.046016 4.535 0.000
L1.Steiermark 0.140773 0.060608 2.323 0.020
L1.Tirol 0.055106 0.048815 1.129 0.259
L1.Vorarlberg 0.145288 0.043191 3.364 0.001
L1.Wien 0.129317 0.080004 1.616 0.106
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.422728 0.043377 9.745 0.000
L1.Burgenland -0.005380 0.025308 -0.213 0.832
L1.Kärnten -0.020800 0.013040 -1.595 0.111
L1.Niederösterreich 0.193475 0.052643 3.675 0.000
L1.Oberösterreich 0.234571 0.052441 4.473 0.000
L1.Salzburg 0.039382 0.026720 1.474 0.141
L1.Steiermark -0.020639 0.035193 -0.586 0.558
L1.Tirol 0.090295 0.028345 3.186 0.001
L1.Vorarlberg 0.047691 0.025080 1.902 0.057
L1.Wien 0.021868 0.046456 0.471 0.638
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.030434 0.089967 0.155934 0.135917 0.075288 0.077483 0.019120 0.201200
Kärnten 0.030434 1.000000 -0.030779 0.131003 0.045826 0.079998 0.446829 -0.073751 0.091563
Niederösterreich 0.089967 -0.030779 1.000000 0.303311 0.124100 0.258260 0.060681 0.148975 0.271159
Oberösterreich 0.155934 0.131003 0.303311 1.000000 0.214847 0.286605 0.165673 0.128557 0.221184
Salzburg 0.135917 0.045826 0.124100 0.214847 1.000000 0.121610 0.078281 0.106673 0.124825
Steiermark 0.075288 0.079998 0.258260 0.286605 0.121610 1.000000 0.130785 0.096532 0.015234
Tirol 0.077483 0.446829 0.060681 0.165673 0.078281 0.130785 1.000000 0.061547 0.145469
Vorarlberg 0.019120 -0.073751 0.148975 0.128557 0.106673 0.096532 0.061547 1.000000 -0.014068
Wien 0.201200 0.091563 0.271159 0.221184 0.124825 0.015234 0.145469 -0.014068 1.000000